package com.haitaoit.chengquan.module.center.activity.order;

import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.haitaoit.chengquan.R;
import com.haitaoit.chengquan.base.BackCall;
import com.haitaoit.chengquan.base.BaseActivity;
import com.haitaoit.chengquan.module.car.activity.OrderPayActivity;
import com.haitaoit.chengquan.module.center.activity.return_goods.ApplyReturnActivity;
import com.haitaoit.chengquan.module.center.activity.return_goods.BackReturnActivity;
import com.haitaoit.chengquan.module.center.activity.return_goods.PlyReturnActivity;
import com.haitaoit.chengquan.module.center.activity.yuyue.MyBuyEvaluateActivity;
import com.haitaoit.chengquan.module.center.adapter.order.MyOrderAdapter;
import com.haitaoit.chengquan.module.center.model.MyOrderDetailModel;
import com.haitaoit.chengquan.module.center.model.MyOrderModel;
import com.haitaoit.chengquan.utils.Constant;
import com.haitaoit.chengquan.utils.DateTimeUtil;
import com.haitaoit.chengquan.utils.DialogUtil;
import com.haitaoit.chengquan.utils.GetSign;
import com.haitaoit.chengquan.utils.HttpUtilsSingle;
import com.haitaoit.chengquan.utils.NameValuePairSign;
import com.haitaoit.chengquan.utils.PreferenceUtils;
import com.haitaoit.chengquan.utils.ToastUtils;
import com.haitaoit.chengquan.view.MyListView;
import com.haitaoit.chengquan.view.PullToRefreshBase;
import com.haitaoit.chengquan.view.PullToRefreshScrollView;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class MyOrderActivity extends BaseActivity implements PullToRefreshBase.OnRefreshListener<ScrollView> {
    @ViewInject(R.id.pull_to_refresh_scrollview)
    PullToRefreshScrollView pullrefreshscrollview;
    @ViewInject(R.id.order_all_num)
    TextView                order_all_num;
    @ViewInject(R.id.order_nopay_num)
    TextView                order_nopay_num;
    @ViewInject(R.id.order_already_send_num)
    TextView                order_already_send_num;
    @ViewInject(R.id.order_already_get_num)
    TextView                order_already_get_num;
    @ViewInject(R.id.order_already_eva_num)
    TextView                order_already_eva_num;
    @ViewInject(R.id.order_all)
    TextView                order_all;
    @ViewInject(R.id.order_nopay)
    TextView                order_nopay;
    @ViewInject(R.id.order_already_send)
    TextView                order_already_send;
    @ViewInject(R.id.order_already_get)
    TextView                order_already_get;
    @ViewInject(R.id.order_already_eva)
    TextView                order_already_eva;
    @ViewInject(R.id.order_line1)
    View                    order_line1;
    @ViewInject(R.id.order_line2)
    View                    order_line2;
    @ViewInject(R.id.order_line3)
    View                    order_line3;
    @ViewInject(R.id.order_line4)
    View                    order_line4;
    @ViewInject(R.id.order_line5)
    View                    order_line5;

    private LinearLayout null_information_layout;
    private MyListView   listView;
    private ScrollView   mScrollView;
    private EditText     search_et;

    private boolean isFrist    = true;
    private int     page       = 1;
    private String  order_type = "all";
    private ToastUtils     toast;
    private Dialog         dlg;
    private MyOrderAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView_V(R.layout.activity_my_order);
        setTitle_V("商城订单");
        setLeftShow(1, R.mipmap.left);
        backLeft_V();
        ViewUtils.inject(this);


        View view = LayoutInflater.from(this).inflate(R.layout.scrollview_listview_layout2, null);
        findViewById(R.id.search_LL).setVisibility(View.VISIBLE);
        null_information_layout = (LinearLayout) view.findViewById(R.id.null_information_layout);
        listView = (MyListView) view.findViewById(R.id.scrollview_listview);
        search_et = (EditText) findViewById(R.id.search_et);
        search_et.setHint("请输入商品名称或订单号");
        findViewById(R.id.search_img).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (search_et.getText().toString().equals("")) {
                    ToastUtils.showToast("请输入商品名称或订单号");
                } else {
                    isFrist = true;
                    page = 1;
                    httpGetuser_order_list();
                }
            }
        });

        pullrefreshscrollview.setPullLoadEnabled(true);
        pullrefreshscrollview.setPullRefreshEnabled(true);
        pullrefreshscrollview.setOnRefreshListener(this);
        pullrefreshscrollview.setLastUpdatedLabel(DateTimeUtil
                .getFormatDateTime(DateTimeUtil.getCurrTimestamp()));
        mScrollView = pullrefreshscrollview.getRefreshableView();
        mScrollView.setFillViewport(true);
        mScrollView.setVerticalScrollBarEnabled(false);
        mScrollView.addView(view);

        order_type = getIntent().getStringExtra("order_type");
        if ("all".equals(order_type)) {
            setColor();
            order_all.setTextColor(getResources().getColor(R.color.app_color));
            order_line1.setVisibility(View.VISIBLE);
        } else if ("nopay".equals(order_type)) {
            setColor();
            order_nopay.setTextColor(getResources().getColor(R.color.app_color));
            order_line2.setVisibility(View.VISIBLE);
        } else if ("already_send".equals(order_type)) {
            setColor();
            order_already_send.setTextColor(getResources().getColor(R.color.app_color));
            order_line3.setVisibility(View.VISIBLE);
        } else if ("already_get".equals(order_type)) {
            setColor();
            order_already_get.setTextColor(getResources().getColor(R.color.app_color));
            order_line4.setVisibility(View.VISIBLE);
        } else if ("already_eva".equals(order_type)) {
            setColor();
            order_already_eva.setTextColor(getResources().getColor(R.color.app_color));
            order_line5.setVisibility(View.VISIBLE);
        }

        adapter = new MyOrderAdapter(this);
        adapter.setBackCall(backCall);
        listView.setAdapter(adapter);

    }

    @Override
    protected void onResume() {
        super.onResume();
        httpGetuser_order_list();
    }

    //    @Override
    //    protected void onResume() {
    //        isFrist = true;
    //        page = 1;
    //        httpGetuser_order_list();
    //        super.onResume();
    //    }

    @OnClick({R.id.order_all, R.id.order_nopay, R.id.order_already_send, R.id.order_already_get,
            R.id.order_already_eva,})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.order_all:// 全部
                setColor();
                order_all.setTextColor(getResources().getColor(R.color.app_color));
                order_line1.setVisibility(View.VISIBLE);

                order_type = "all";
                break;
            case R.id.order_nopay:// 待付款
                setColor();
                order_nopay.setTextColor(getResources().getColor(R.color.app_color));
                order_line2.setVisibility(View.VISIBLE);

                order_type = "nopay";
                break;
            case R.id.order_already_send:// 待发货
                setColor();
                order_already_send.setTextColor(getResources().getColor(R.color.app_color));
                order_line3.setVisibility(View.VISIBLE);

                order_type = "already_send";
                break;
            case R.id.order_already_get:// 待收货
                setColor();
                order_already_get.setTextColor(getResources().getColor(R.color.app_color));
                order_line4.setVisibility(View.VISIBLE);

                order_type = "already_get";
                break;
            case R.id.order_already_eva:// 待评价
                setColor();
                order_already_eva.setTextColor(getResources().getColor(R.color.app_color));
                order_line5.setVisibility(View.VISIBLE);

                order_type = "already_eva";
                break;
        }
        isFrist = true;
        page = 1;
        httpGetuser_order_list();
    }

    BackCall backCall = new BackCall() {
        @Override
        public void deal(int which, Object... obj) {
            final int position = (Integer) obj[0];
            Intent intent = new Intent();
            switch (which) {
                case R.id.order_itemll:// 详情
                case R.id.scrollview_listview:// 详情
                    intent.setClass(MyOrderActivity.this, MyOrderDetailActivity.class);
                    intent.putExtra("order_type", order_type);
                    intent.putExtra("order_no", adapter.getList().get(position).getOrder_no());
                    startActivity(intent);
                    break;
                case R.id.go_eva:// 去评价
                    httpGetorder_model(adapter.getList().get(position).getOrder_no(),position,adapter.getList().get(position).getList_goods().get(position).getImg_url());
                    break;
                case R.id.cancel_order:// 取消订单
                    dlg = DialogUtil.showInfoDialog1(MyOrderActivity.this, "提示",
                            "您确定要取消该订单吗？", "确定取消", "再想想", new BackCall() {
                                public void deal(int which, Object... obj) {
                                    switch (which) {
                                        case R.id.confirm:// 确定
                                            httpGetcancel_order(adapter.getList().get(position).getOrder_no());
                                            break;
                                    }
                                    super.deal(which);
                                }
                            });
                    dlg.setCanceledOnTouchOutside(true);
                    dlg.show();
                    break;
                case R.id.go_pay:// 付款
                    intent.setClass(MyOrderActivity.this, OrderPayActivity.class);
                    intent.putExtra("order_no", adapter.getList().get(position).getOrder_no());
                    intent.putExtra("order_amount", adapter.getList().get(position).getOrder_amount());
                    startActivity(intent);
                    break;
                case R.id.remind_goods:// 提醒发货
                    httpGetshipment_remind(adapter.getList().get(position).getOrder_no());
                    break;
                case R.id.apply_return_goods:// 申请退货
                    intent.setClass(MyOrderActivity.this, BackReturnActivity.class);
                    intent.putExtra("order_no", adapter.getList().get(position).getOrder_no());
                    intent.putExtra("amount", adapter.getList().get(position).getOrder_amount());
                    intent.putExtra("again", "1");
                    startActivity(intent);
                    break;
                case R.id.apply_refund:// 申请退款
                    intent.setClass(MyOrderActivity.this, PlyReturnActivity.class);
                    intent.putExtra("order_no", adapter.getList().get(position).getOrder_no());
                    intent.putExtra("amount", adapter.getList().get(position).getOrder_amount());
                    intent.putExtra("again", "1");
                    startActivity(intent);
                    break;
                case R.id.apply_change_goods:// 申请换货
                    intent.setClass(MyOrderActivity.this, ApplyReturnActivity.class);
                    intent.putExtra("order_no", adapter.getList().get(position).getOrder_no());
                    intent.putExtra("amount", adapter.getList().get(position).getOrder_amount());
                    intent.putExtra("again", "1");
                    startActivity(intent);
                    break;
                case R.id.check_wuliu:// 查看物流
                    intent.setClass(MyOrderActivity.this, TransportStateActivity.class);
                    intent.putExtra("order_no", adapter.getList().get(position).getOrder_no());
                    startActivity(intent);
                    //        Uri uri = Uri.parse("http://google.com");
                    //        Intent it = new Intent(Intent.ACTION_VIEW, uri);
                    //        startActivity(it);
                    break;
                case R.id.confirm_complete:// 确认收货
                    dlg = DialogUtil.showInfoDialog1(MyOrderActivity.this, "提示",
                            "确认收货？", "确定", "还没有", new BackCall() {
                                public void deal(int which, Object... obj) {
                                    switch (which) {
                                        case R.id.confirm:// 确定
                                            httpGetreceiving_order(adapter.getList().get(position).getOrder_no());
                                            break;
                                    }
                                    super.deal(which);
                                }
                            });
                    dlg.setCanceledOnTouchOutside(true);
                    dlg.show();
                    break;
                case R.id.detele_order:// 删除订单
                    dlg = DialogUtil.showInfoDialog1(MyOrderActivity.this, "提示",
                            "您确定要删除该订单吗？", "确定", "取消", new BackCall() {
                                public void deal(int which, Object... obj) {
                                    switch (which) {
                                        case R.id.confirm:// 确定
                                            httpGetdel_order(adapter.getList().get(position).getOrder_no());
                                            break;
                                    }
                                    super.deal(which);
                                }
                            });
                    dlg.setCanceledOnTouchOutside(true);
                    dlg.show();
                    break;
            }
            super.deal(which, obj);
        }
    };

    // 列表
    private void httpGetuser_order_list() {
        int status = 1;
        if ("all".equals(order_type)) {
            status = 1;
        } else if ("nopay".equals(order_type)) {
            status = 2;
        } else if ("already_send".equals(order_type)) {
            status = 3;
        } else if ("already_get".equals(order_type)) {
            status = 4;
        } else if ("already_eva".equals(order_type)) {
            status = 5;
        }

        List<NameValuePairSign> list = new ArrayList<NameValuePairSign>();
        list.add(new NameValuePairSign("user_id", PreferenceUtils.getPrefString("user_id", "")));
        list.add(new NameValuePairSign("status", status + ""));
        list.add(new NameValuePairSign("name", search_et.getText().toString()));
        list.add(new NameValuePairSign("page", page + ""));
        list.add(new NameValuePairSign("pagesize", Constant.PageSize));
        String sign = GetSign.genPackageSign(list);

        RequestParams params = new RequestParams();
        params.addQueryStringParameter("user_id", PreferenceUtils.getPrefString("user_id", ""));
        params.addQueryStringParameter("status", status + "");
        params.addQueryStringParameter("name", search_et.getText().toString());
        params.addQueryStringParameter("page", page + "");
        params.addQueryStringParameter("pagesize", Constant.PageSize);
        params.addQueryStringParameter("sign", sign);
        showProgrees("");
        HttpUtilsSingle.doGet(this, false, Constant.Getuser_order_list, params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> arg0) {
                String result = arg0.result.toString();
                List<MyOrderModel> new_list = new ArrayList<MyOrderModel>();
                try {
                    JSONObject json = new JSONObject(result);
                    String Errcode = json.getString("ErrCode");
                    String Errmsg = json.getString("ErrMsg");
                    String Response = json.getString("Response");
                    Gson gson = new Gson();
                    switch (Integer.valueOf(Errcode)) {
                        case 1:// 失败
                            ToastUtils.showToast(Errmsg);
                            pullrefreshscrollview.onPullDownRefreshComplete();
                            pullrefreshscrollview.onPullUpRefreshComplete();
                            new_list = new ArrayList<MyOrderModel>();
                            hideProgree();
                            break;
                        case 0:// 成功
                            JSONObject js = new JSONObject(Response);
                            order_all_num.setText(js.getString("all_count"));
                            order_nopay_num.setText(js.getString("pending_payment_count"));
                            order_already_send_num.setText(js.getString("tobe_shipped_count"));
                            order_already_get_num.setText(js.getString("receipt_goods_count"));
                            order_already_eva_num.setText(js.getString("tobe_evaluated_count"));

                            if (js.getString("all_count").equals("0")) {
                                order_all_num.setVisibility(View.GONE);
                            } else {
                                order_all_num.setVisibility(View.VISIBLE);
                            }
                            if (js.getString("pending_payment_count").equals("0")) {
                                order_nopay_num.setVisibility(View.GONE);
                            } else {
                                order_nopay_num.setVisibility(View.VISIBLE);
                            }
                            if (js.getString("tobe_shipped_count").equals("0")) {
                                order_already_send_num.setVisibility(View.GONE);
                            } else {
                                order_already_send_num.setVisibility(View.VISIBLE);
                            }
                            if (js.getString("receipt_goods_count").equals("0")) {
                                order_already_get_num.setVisibility(View.GONE);
                            } else {
                                order_already_get_num.setVisibility(View.VISIBLE);
                            }
                            if (js.getString("tobe_evaluated_count").equals("0")) {
                                order_already_eva_num.setVisibility(View.GONE);
                            } else {
                                order_already_eva_num.setVisibility(View.VISIBLE);
                            }

                            new_list = gson.fromJson(js.getString("list_order"),
                                    new TypeToken<List<MyOrderModel>>() {
                                    }.getType());
                            hideProgree();
                            break;
                        case 2:// 暂无内容
                            pullrefreshscrollview.onPullDownRefreshComplete();
                            pullrefreshscrollview.onPullUpRefreshComplete();
                            new_list = new ArrayList<MyOrderModel>();
                            hideProgree();
                            break;
                    }
                    if (isFrist) {
                        if (isNullDate(new_list)) {
                            adapter.setList(new_list);
                            adapter.notifyDataSetChanged();
                        }
                        pullrefreshscrollview.onPullDownRefreshComplete();
                    } else {
                        List<MyOrderModel> allList = adapter.getList();
                        allList.addAll(new_list);
                        adapter.setList(allList);
                        adapter.notifyDataSetChanged();
                        pullrefreshscrollview.onPullUpRefreshComplete();
                    }
                    hideProgree();
                } catch (JSONException e) {
                    e.printStackTrace();
                    hideProgree();
                }
            }

            @Override
            public void onFailure(HttpException arg0, String arg1) {
                ToastUtils.showToast("获取数据失败,请检查网络");
                hideProgree();
            }
        });
    }

    // 取消订单
    private void httpGetcancel_order(String order_no) {
        List<NameValuePairSign> list = new ArrayList<NameValuePairSign>();
        list.add(new NameValuePairSign("user_id", PreferenceUtils.getPrefString("user_id", "")));
        list.add(new NameValuePairSign("order_no", order_no));
        String sign = GetSign.genPackageSign(list);

        RequestParams params = new RequestParams();
        params.addQueryStringParameter("user_id", PreferenceUtils.getPrefString("user_id", ""));
        params.addQueryStringParameter("order_no", order_no);
        params.addQueryStringParameter("sign", sign);
        showProgrees("");
        HttpUtilsSingle.doGet(this, false, Constant.Getcancel_order, params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> arg0) {
                String jsonString = arg0.result.toString();
                JSONObject json;
                try {
                    json = new JSONObject(jsonString);
                    String Errcode = json.getString("ErrCode");
                    String Errmsg = json.getString("ErrMsg");
                    String Response = json.getString("Response");
                    switch (Integer.valueOf(Errcode)) {
                        case 1:// 失败
                            ToastUtils.showToast(Errmsg);
                            hideProgree();
                            return;
                        case 0:// 成功
                            ToastUtils.showToast(Errmsg);
                            isFrist = true;
                            page = 1;
                            httpGetuser_order_list();
                            hideProgree();
                            return;
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    hideProgree();
                }
            }

            public void onFailure(HttpException arg0, String arg1) {
                ToastUtils.showToast("获取数据失败,请检查网络");
                hideProgree();
            }
        });
    }

    // 提醒发货
    private void httpGetshipment_remind(String order_no) {
        List<NameValuePairSign> list = new ArrayList<NameValuePairSign>();
        list.add(new NameValuePairSign("user_id", PreferenceUtils.getPrefString("user_id", "")));
        list.add(new NameValuePairSign("order_no", order_no));
        String sign = GetSign.genPackageSign(list);

        RequestParams params = new RequestParams();
        params.addQueryStringParameter("user_id", PreferenceUtils.getPrefString("user_id", ""));
        params.addQueryStringParameter("order_no", order_no);
        params.addQueryStringParameter("sign", sign);
        showProgrees("");
        HttpUtilsSingle.doGet(this, false, Constant.Getshipment_remind, params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> arg0) {
                String jsonString = arg0.result.toString();
                JSONObject json;
                try {
                    json = new JSONObject(jsonString);
                    String Errcode = json.getString("ErrCode");
                    String Errmsg = json.getString("ErrMsg");
                    String Response = json.getString("Response");
                    switch (Integer.valueOf(Errcode)) {
                        case 1:// 失败
                            ToastUtils.showToast(Errmsg);
                            hideProgree();
                            return;
                        case 0:// 成功
                            ToastUtils.showToast(Errmsg);
                            hideProgree();
                            return;
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    hideProgree();
                }
            }

            public void onFailure(HttpException arg0, String arg1) {
                ToastUtils.showToast("获取数据失败,请检查网络");
                hideProgree();
            }
        });
    }

    // 确认收货订单
    private void httpGetreceiving_order(String order_no) {
        List<NameValuePairSign> list = new ArrayList<NameValuePairSign>();
        list.add(new NameValuePairSign("user_id", PreferenceUtils.getPrefString("user_id", "")));
        list.add(new NameValuePairSign("order_no", order_no));
        String sign = GetSign.genPackageSign(list);

        RequestParams params = new RequestParams();
        params.addQueryStringParameter("user_id", PreferenceUtils.getPrefString("user_id", ""));
        params.addQueryStringParameter("order_no", order_no);
        params.addQueryStringParameter("sign", sign);
        showProgrees("");
        HttpUtilsSingle.doGet(this, false, Constant.Getreceiving_order, params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> arg0) {
                String jsonString = arg0.result.toString();
                JSONObject json;
                try {
                    json = new JSONObject(jsonString);
                    String Errcode = json.getString("ErrCode");
                    String Errmsg = json.getString("ErrMsg");
                    String Response = json.getString("Response");
                    switch (Integer.valueOf(Errcode)) {
                        case 1:// 失败
                            ToastUtils.showToast(Errmsg);
                            hideProgree();
                            return;
                        case 0:// 成功
                            ToastUtils.showToast(Errmsg);
                            isFrist = true;
                            page = 1;
                            httpGetuser_order_list();
                            hideProgree();
                            return;
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    hideProgree();
                }
            }

            public void onFailure(HttpException arg0, String arg1) {
                ToastUtils.showToast("获取数据失败,请检查网络");
                hideProgree();
            }
        });
    }

    // 删除订单
    private void httpGetdel_order(String order_no) {
        List<NameValuePairSign> list = new ArrayList<NameValuePairSign>();
        list.add(new NameValuePairSign("user_id", PreferenceUtils.getPrefString("user_id", "")));
        list.add(new NameValuePairSign("order_no", order_no));
        String sign = GetSign.genPackageSign(list);

        RequestParams params = new RequestParams();
        params.addQueryStringParameter("user_id", PreferenceUtils.getPrefString("user_id", ""));
        params.addQueryStringParameter("order_no", order_no);
        params.addQueryStringParameter("sign", sign);
        showProgrees("");
        HttpUtilsSingle.doGet(this, false, Constant.Getdel_order, params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> arg0) {
                String jsonString = arg0.result.toString();
                JSONObject json;
                try {
                    json = new JSONObject(jsonString);
                    String Errcode = json.getString("ErrCode");
                    String Errmsg = json.getString("ErrMsg");
                    String Response = json.getString("Response");
                    switch (Integer.valueOf(Errcode)) {
                        case 1:// 失败
                            ToastUtils.showToast(Errmsg);
                            hideProgree();
                            return;
                        case 0:// 成功
                            ToastUtils.showToast(Errmsg);
                            isFrist = true;
                            page = 1;
                            httpGetuser_order_list();
                            hideProgree();
                            return;
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    hideProgree();
                }
            }

            public void onFailure(HttpException arg0, String arg1) {
                ToastUtils.showToast("获取数据失败,请检查网络");
                hideProgree();
            }
        });
    }

    public void setColor() {
        order_all.setTextColor(getResources().getColor(R.color.black_text));
        order_nopay.setTextColor(getResources().getColor(R.color.black_text));
        order_already_send.setTextColor(getResources().getColor(R.color.black_text));
        order_already_get.setTextColor(getResources().getColor(R.color.black_text));
        order_already_eva.setTextColor(getResources().getColor(R.color.black_text));

        order_line1.setVisibility(View.INVISIBLE);
        order_line2.setVisibility(View.INVISIBLE);
        order_line3.setVisibility(View.INVISIBLE);
        order_line4.setVisibility(View.INVISIBLE);
        order_line5.setVisibility(View.INVISIBLE);
    }

    /**
     * @tab 判断listview是否有值
     */
    private boolean isNullDate(List<MyOrderModel> rewordList) {
        if (rewordList == null || rewordList.size() == 0) {
            null_information_layout.setVisibility(View.VISIBLE);
            listView.setVisibility(View.GONE);
            return false;
        } else {
            null_information_layout.setVisibility(View.GONE);
            listView.setVisibility(View.VISIBLE);
            return true;
        }
    }

    @Override
    public void onPullDownToRefresh(PullToRefreshBase<ScrollView> refreshView) {
        pullrefreshscrollview.setLastUpdatedLabel(DateTimeUtil
                .getFormatDateTime(DateTimeUtil.getCurrTimestamp()));
        isFrist = true;
        page = 1;
        httpGetuser_order_list();
    }

    @Override
    public void onPullUpToRefresh(PullToRefreshBase<ScrollView> refreshView) {
        pullrefreshscrollview.setLastUpdatedLabel(DateTimeUtil
                .getFormatDateTime(DateTimeUtil.getCurrTimestamp()));
        isFrist = false;
        page++;
        httpGetuser_order_list();
    }
    // 我的订单详细
    private void httpGetorder_model(final String order_no, final int position, final String img_url) {
        List<NameValuePairSign> list = new ArrayList<NameValuePairSign>();
        list.add(new NameValuePairSign("user_id", PreferenceUtils.getPrefString("user_id", "")));
        list.add(new NameValuePairSign("order_no", order_no));
        String sign = GetSign.genPackageSign(list);

        RequestParams params = new RequestParams();
        params.addQueryStringParameter("user_id", PreferenceUtils.getPrefString("user_id", ""));
        params.addQueryStringParameter("order_no", order_no);
        params.addQueryStringParameter("sign", sign);

        HttpUtilsSingle.doGet(this, false, Constant.Getorder_model, params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> arg0) {
                String jsonString = arg0.result.toString();
                JSONObject json;
                try {
                    json = new JSONObject(jsonString);
                    String Errcode = json.getString("ErrCode");
                    String Errmsg = json.getString("ErrMsg");
                    String Response = json.getString("Response");
                    Gson gson = new Gson();
                    switch (Integer.valueOf(Errcode)) {
                        case 1:// 失败
                            ToastUtils.showToast(Errmsg);
                            return;
                        case 0:// 成功
                            MyOrderDetailModel model = gson.fromJson(Response, MyOrderDetailModel.class);
                            String order_goods_id = model.getList_goods().get(position).getOrder_goods_id();
                            //                    直接跳转到评价界面
                            //                    intent.setClass(MyOrderActivity.this, SendEvaluateActivity.class);
                            Intent intent = new Intent();
                            intent.setClass(MyOrderActivity.this, MyBuyEvaluateActivity.class);
                            intent.putExtra("order_no", order_no);
                            intent.putExtra("order_goods_id", order_goods_id);
                            intent.putExtra("image_uri", img_url);
                            startActivity(intent);

                            return;
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            public void onFailure(HttpException arg0, String arg1) {
                ToastUtils.showToast("获取数据失败,请检查网络");
            }
        });
    }
}
